package com.hp.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.hp.ssm.entity.User;
import com.hp.ssm.mapper.UserMapper;
import com.hp.ssm.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public List<User> findAll(User user,Integer page, Integer limit) {
        // TODO Auto-generated method stub
        //使用PageHelper.startPage静态方法调用
        //startPage后面的第一个对数据库操作的方法，将自动进行分页，sql语句无需添加limit关键字
        PageHelper.startPage(page, limit);//page为申请查询的页码，limit为一页显示多少条数据
        //userDao.findAll();//PageHelper.startPage()后面必须紧接查询数据的方法
        return userMapper.findAll(user);
    }

    @Override
    public int add(User user) {
        return userMapper.add(user);
    }

    @Override
    public User showById(Integer aid) {
        return userMapper.showById(aid);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }

    @Override
    public int del(Integer aid) {
        return userMapper.del(aid);
    }

    @Override
    public List<User> delfindAll(User user,Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return userMapper.delfindAll(user);
    }

    @Override
    public int recover(Integer aid) {
        return userMapper.recover(aid);
    }
}
